package com.eims.sls_app.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.XmlResourceParser;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import bls.juejin.cn.R;
import com.eims.sls_app.dataaccess.utils.HttpUtils;
import com.eims.sls_app.protocol.MD5;
import com.eims.sls_app.protocol.RspBodyBaseBean;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.AppTools;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.BaseHelper;
import com.eims.sls_app.utils.LotteryUtils;
import com.eims.sls_app.utils.RequestUtil;
import com.eims.sls_app.view.MyBankSpinner;
import com.eims.sls_app.view.MyToast;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 账户信息
 * 
 * @author SLS003
 */
public class AccountInformationActivity extends MyBaseActivity {
	private static final String TAG = "AccountInformation";
	private Activity context = AccountInformationActivity.this;
	private TextView accInfo_tv_mobilephone; // 手机号码
	private TextView tv_tip_info; // 温馨提示
	private EditText accInfo_tv_uname; // 用户名
	private EditText accInfo_tv_qqnumber;// qq号码
	public EditText bankinfo_et_soft; // 问题
	private EditText bangkinfo_et_answer; // 答案
	private EditText tv_name; // 真实姓名rr
	private EditText tv_cardNum; // 身份证号
	public TextView tv_bankName; // 银行名称
	public TextView tv_bankLocation; // 开户地点
	private EditText tv_fullName; // 全称
	private EditText tv_bankNum; // 银行号
	private ImageButton btn_back;
	private ImageButton bankinfo_btn_soft;// 安全问题图标
	private String opt, auth, info, time, imei, crc; // 格式化后的参数
	private LinearLayout layout_question;// 问题及答案布局
	private LinearLayout layout_mobile;// 箭头
	private LinearLayout layout_bankname;
	private LinearLayout layout_bankadress;
	private LinearLayout layout_mb;// 布局
	private LinearLayout layout_yh;
	private LinearLayout layout_adress;

	private List<Map<String, String>> listBank = new ArrayList<Map<String, String>>();
	private List<Map<String, String>> listProvince = new ArrayList<Map<String, String>>();
	private List<Map<String, String>> listCity = new ArrayList<Map<String, String>>();
	private List<Map<String, String>> listQuestion = new ArrayList<Map<String, String>>();

	public int bank_index = -1;
	public int province_index = -1;
	public int city_index = -1;
	public int question_index = -1;
	private String mobile;
	private String uname, qqNumber, bankTypeId, bankId, bankCardNumber,
			bankInCityId, realityName, idCardNO, securityQuestionId,
			securityQuestionAnswer, cityId, bankInProvinceId;

	private MyBankSpinner spinner_bank, spinner_province, spinner_city,
			spinner_question;
	private Button btn_improve;
	private MyAsynTask myAsynTask;
	private MyHandler myHandler;

	public static List<Activity> list = new ArrayList<Activity>();
	private ProgressDialog dialog;
	private String errormsg = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_account_information);
		App.activityS.add(this);
		list.add(this);
		init();
		myAsynTask = new MyAsynTask();
		myAsynTask.execute();
		// getData(listProvince, "provincename", R.xml.province);
		// getData(listBank, "bankname", R.xml.bank);
		getData(listQuestion, "question", R.xml.question);
	}

	/**
	 * 初始化参数
	 */
	private void init() {
		if (null != App.user && App.user.getUid() != null) {
			myHandler = new MyHandler();
			opt = "41";
			time = RspBodyBaseBean.getTime();
			imei = RspBodyBaseBean.getIMEI(this);
			info = "{}";
			String key = App.key;
			crc = RspBodyBaseBean.getCrc(time, imei, key, info,
					App.user.getUid());
			auth = RspBodyBaseBean.getAuth(crc, time, imei,
					App.user.getUid());
		} else {
			RequestUtil requestUtil = new RequestUtil(context, false, 0) {
				@Override
				public void responseCallback(JSONObject reponseJson) {
					String retult = AppTools.doLogin(reponseJson);
					if ("0".equals(retult)) {
						SharedPreferences settings = context
								.getSharedPreferences("app_user", 0);
						boolean isLogin = false;
						String pass = "";
						if (settings.contains("isLogin")) {
							isLogin = settings.getBoolean("isLogin", false);
						}
						if (isLogin) {
							// 判断是否有存 密码
							if (settings.contains("pass")) {
								pass = settings.getString("pass", null);
							}
						}
						if (null != App.user)
							App.user.setUserPass(pass);
						if (RequestUtil.DEBUG)
							Log.i(TAG, "自动登录成功");
					} else {
						if (RequestUtil.DEBUG)
							Log.i(TAG, "自动登录失败" + retult);
					}
				}

				@Override
				public void responseError(VolleyError error) {
					if (RequestUtil.DEBUG)
						Log.i(TAG, "自动登录失败" + error.getMessage());
				}
			};
			requestUtil.doAutoLogin();
		}
	}

	/**
	 * 解析银行和省的XML
	 */
	private void getData(List<Map<String, String>> list, String name2, int xml) {
		// 先清除
		list.clear();
		XmlResourceParser xrp = getResources().getXml(xml);
		try {
			Map<String, String> map = null;
			// 直到文档的结尾处
			while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
				// 如果遇到了开始标签
				if (xrp.getEventType() == XmlResourceParser.START_TAG) {
					String tagName = xrp.getName();// 获取标签的名字
					if (tagName.equals("row")) {
						map = new HashMap<String, String>();
						String id = xrp.getAttributeValue(null, "id");// 通过属性名来获取属性值
						String nm = xrp.getAttributeValue(null, name2);// 通过属性名来获取属性值
						map.put("id", id);
						map.put("name", nm);
						list.add(map);
					}
				}
				xrp.next();// 获取解析下一个事件
			}
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 解析城市的XML
	 */
	/*
	 * private void getData2(String bankInProvinceId) { listCity.clear();
	 * XmlResourceParser xrp = getResources().getXml(R.xml.city); try { //
	 * 直到文档的结尾处 while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
	 * // 如果遇到了开始标签 if (xrp.getEventType() == XmlResourceParser.START_TAG) {
	 * String tagName = xrp.getName();// 获取标签的名字 if (tagName.equals("row")) {
	 * Map<String, String> map = new HashMap<String, String>(); String proId =
	 * xrp .getAttributeValue(null, "provinceid");// 通过属性名来获取属性值 if
	 * (bankInProvinceId.equals(proId)) { String id =
	 * xrp.getAttributeValue(null, "id");// 通过属性名来获取属性值 String cityname =
	 * xrp.getAttributeValue(null, "cityname");// 通过属性名来获取属性值 map.put("id", id);
	 * map.put("name", cityname); listCity.add(map); } } } xrp.next();//
	 * 获取解析下一个事件 } } catch (XmlPullParserException e) { e.printStackTrace(); }
	 * catch (IOException e) { e.printStackTrace(); } }
	 */

	/*
	 * public boolean changCity() { // 判断是否选择了省份 if (null!=spinner_city &&
	 * spinner_city.isShowing()) { spinner_city.dismiss(); } if (province_index
	 * != -1) { for (Object o : listProvince.get(province_index).entrySet()) {
	 * Map.Entry entry = (Map.Entry) o; String key = (String) entry.getKey(); if
	 * ("id".equals(key)) { bankInProvinceId = (String) entry.getValue();
	 * getData2(bankInProvinceId); } } spinner_city = new MyBankSpinner(context,
	 * listCity, city_index, App.CITY_TYPE, R.style.dialog);
	 * spinner_city.show(); return true; } else { return false; } }
	 */
	/**
	 * 判断银行卡是否绑定
	 */
	private boolean chechBank() {
		if (null == App.user.getBangNum()
				|| App.user.getBangNum().length() == 0) {
			String[] values = { opt, auth, info };
			String result = HttpUtils.doPost(App.names, values,
					App.path);
			System.out.println("银行信息：" + result);
			try {
				JSONObject object = new JSONObject(result);
				String isBinded = object.optString("isBinded");
				if ("Yes".equals(isBinded)) {
					App.user.setName(object.optString("name"));
					App.user.setRealityName(object
							.optString("realityName").substring(0,1)+"**");
					
					App.user.setQqNumber(object.optString("qqnumber"));
					
					//App.user.setQqNumber(object.optString("qqnumber"));
					App.user.setIdcardnumber(object
							.optString("idCardnumber").substring(0, 14)+"****");
					App.user.setMobile(object.optString("mobile"));
					App.user
							.setBangNum(object.optString("bankCardNumber"));
					App.user.setProvinceName(object
							.optString("provinceName"));
					App.user.setCityName(object.optString("cityName"));
					App.user.setBankName(object.optString("bankTypeName"));
					App.user.setFullName(object
							.optString("branchBankName"));
					App.user.setSecurityQuestionId(object
							.optString("securityquestion"));
					String str2 = App.user.getBangNum();
					App.user.setBangNum(str2.substring(0, 3) + "***"
							+ str2.substring(str2.length() - 3));
					return true;
				} else {
					App.user.setName(object.optString("name"));
					App.user.setMobile(object.optString("mobile"));
					//App.user.setQqNumber(object.optString("qqnumber"));
					
						App.user.setQqNumber(object.optString("qqnumber"));
					
					App.user.setRealityName(object
							.optString("realityName").substring(0, 1)+"**");
					App.user.setIdcardnumber(object
							.optString("idCardnumber").substring(0, 14)+"****");
					App.user.setSecurityQuestionId(object
							.optString("securityQuestionId"));
					App.user.setSecurityQuestionAnswer(object
							.optString("securityQuestionAnswer"));
				}
			} catch (Exception e) {

				e.printStackTrace();
				Log.e("x", "AccountInfornation异常" + e.getMessage());
			}
		} else {

			return true;
		}
		return false;
	}

	/**
	 * 初始化UI
	 */
	private void findView() {
		tv_name = (EditText) this.findViewById(R.id.accInfo_tv_name2);
		tv_cardNum = (EditText) this.findViewById(R.id.accInfo_tv_cardNum2);
		// tv_bankLocation = (TextView)
		// this.findViewById(R.id.accInfo_tv_location2);
		tv_tip_info = (TextView) this.findViewById(R.id.tv_tip_info);
		// tv_bankName = (TextView)
		// this.findViewById(R.id.accInfo_tv_bankName2);
		// tv_fullName = (EditText)
		// this.findViewById(R.id.accInfo_tv_fullName2);
		tv_bankNum = (EditText) this.findViewById(R.id.accInfo_tv_bankNum2);
		accInfo_tv_mobilephone = (TextView) this
				.findViewById(R.id.accInfo_tv_mobilephone);// 手机号
		accInfo_tv_uname = (EditText) this.findViewById(R.id.accInfo_tv_uname);
		accInfo_tv_qqnumber = (EditText) this
				.findViewById(R.id.accInfo_tv_qqnumber);
		bangkinfo_et_answer = (EditText) this
				.findViewById(R.id.bangkinfo_et_answer);
		bankinfo_et_soft = (EditText) this.findViewById(R.id.bankinfo_et_soft);
		layout_question = (LinearLayout) this
				.findViewById(R.id.layout_question);
		layout_mobile = (LinearLayout) this.findViewById(R.id.layout_mobile);// 手机号码
		// layout_bankname = (LinearLayout)
		// this.findViewById(R.id.layout_bankname);
		// layout_bankadress = (LinearLayout)
		// this.findViewById(R.id.layout_bankadress);
		layout_mb = (LinearLayout) this.findViewById(R.id.layout_mb);// 手机号码
		// layout_yh = (LinearLayout) this.findViewById(R.id.layout_yh);
		// layout_adress = (LinearLayout) this.findViewById(R.id.layout_adress);
		btn_back = (ImageButton) this.findViewById(R.id.btn_back);
		bankinfo_btn_soft = (ImageButton) this
				.findViewById(R.id.bankinfo_btn_soft);
		btn_improve = (Button) this.findViewById(R.id.accInfo_btn_improve);
		btn_back.setOnClickListener(new MyClickListener());
		bankinfo_btn_soft.setOnClickListener(new MyClickListener());
		btn_improve.setOnClickListener(new MyClickListener());
		layout_mb.setOnClickListener(new MyClickListener());
		// layout_yh.setOnClickListener(new MyClickListener());
		// layout_adress.setOnClickListener(new MyClickListener());
		getSiteNameAndPhone();
	}

	/**
	 * 设置不可用/可用和隐藏/显示
	 * 
	 * @param enabled
	 */
	public void setEditTextEnabled(boolean enabled) {
		if (!enabled) {
			layout_mobile.setVisibility(View.GONE);
			// layout_bankname.setVisibility(View.GONE);
			// layout_bankadress.setVisibility(View.GONE);
			btn_improve.setVisibility(View.GONE);
			layout_question.setVisibility(View.GONE);
		} else {

			layout_mobile.setVisibility(View.VISIBLE);
			// layout_bankname.setVisibility(View.VISIBLE);
			// layout_bankadress.setVisibility(View.VISIBLE);
			btn_improve.setVisibility(View.VISIBLE);
			
			if (null != App.user.getSecurityQuestionId()
					&& !"".equals(App.user.getSecurityQuestionId())
					&& null != App.user.getSecurityQuestionAnswer()
					&& !"".equals(App.user.getSecurityQuestionAnswer())) {
				layout_question.setVisibility(View.GONE);
			} else {
				layout_question.setVisibility(View.VISIBLE);
			}

		}
		btn_improve.setEnabled(enabled);
		bankinfo_btn_soft.setEnabled(enabled);
		layout_mb.setEnabled(enabled);
		// layout_yh.setEnabled(enabled);
		// layout_adress.setEnabled(enabled);
		tv_name.setEnabled(enabled);
		tv_cardNum.setEnabled(enabled);
		// tv_bankLocation.setEnabled(enabled);
		// tv_bankName.setEnabled(enabled);
		// tv_fullName.setEnabled(enabled);
		tv_bankNum.setEnabled(enabled);
		accInfo_tv_mobilephone.setEnabled(enabled);
		accInfo_tv_uname.setEnabled(enabled);
		accInfo_tv_qqnumber.setEnabled(enabled);
		bangkinfo_et_answer.setEnabled(enabled);
	}

	public boolean checkInfo() {
		if (null != App.user.getSecurityQuestionId()
				&& !"".equals(App.user.getSecurityQuestionId())
				|| null != App.user.getSecurityQuestionAnswer()
				&& !"".equals(App.user.getSecurityQuestionAnswer())) {
			securityQuestionId = App.user.getSecurityQuestionId();
			securityQuestionAnswer = App.user.getSecurityQuestionAnswer();
		} else {
			securityQuestionId = this.getID(question_index, listQuestion);
			securityQuestionAnswer = bangkinfo_et_answer.getText().toString()
					.trim();
		}// wenti

		if (null != App.user.getIdcardnumber()
				&& !"".equals(App.user.getIdcardnumber())) {
			idCardNO = App.user.getIdcardnumber();
		} else {
			idCardNO = tv_cardNum.getText().toString().trim();
		}// 身份证号码
		mobile = accInfo_tv_mobilephone.getText().toString().trim();
		uname = accInfo_tv_uname.getText().toString().trim();
		qqNumber = accInfo_tv_qqnumber.getText().toString().trim();
		realityName = tv_name.getText().toString().trim();

		// bankTypeId = this.getID(bank_index, listBank);
		// bankInCityId = this.getID(city_index, listCity);
		// bankId=tv_fullName.getText().toString().trim();
		bankCardNumber = tv_bankNum.getText().toString().trim();
		String regExp = "1[0-9]{10}";
		String name_verification = "^[\u4e00-\u9fa5_a-zA-Z]{1,6}$";
		String isIDCard1 = "^\\w+(\\.\\w+)*@(\\w)+((\\.\\w+)+)*$";
		String isIDCard2_verification = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$";

		
		if ("".equals(mobile)) {
			MyToast.getToast(context, "请绑定手机号码").show();
			return false;
		}
		if ("".equals(uname)) {
			MyToast.getToast(context, "请输入用户名").show();
			return false;
		}
		if (!bankCardNumber.matches(isIDCard1)
				|| (!bankCardNumber.matches(regExp))) {
			MyToast.getToast(context, "你输入的支付宝账号有错误");
		}
		// 验证qq数字位数
		if (!"".equals(qqNumber)) {
			byte[] bytes = qqNumber.getBytes();
			if (bytes.length < 6) {
				MyToast.getToast(context, "qq号最少为6位").show();
				return false;
			}
		}
		if ("".equals(qqNumber)) {
			MyToast.getToast(context, "请输入qq号").show();
			return false;
		}
		int charLength = LotteryUtils.getRexStrLength(uname);
		if (charLength < 5 || charLength > 16) {
			MyToast.getToast(context, "用户名为5-16个字符,中文占两个字符").show();
			return false;
		}
		if ("".equals(realityName)) {
			MyToast.getToast(context, "请输入真实姓名").show();
			return false;
		} else {
			if (!realityName.matches(name_verification)) {

				MyToast.getToast(context, "请输入正确的真实姓名").show();
				return false;
			}
		}
		if ("".equals(idCardNO)) {
			MyToast.getToast(context, "请输入身份证号码").show();
			return false;
		}
		// else{
		// if (!idCardNO.matches(isIDCard2_verification)) {
		// MyToast.getToast(context,"请输入正确的身份证号码").show();
		// return false;
		// }
		// }
		/*
		 * if(!isFull()) { MyToast.getToast(context,"请选择银行和开户地点").show(); return
		 * false; }
		 */
		/*
		 * if("".equals(bankId)){ MyToast.getToast(context,"请输入开户支行").show();
		 * return false; }
		 */
		if ("".equals(bankCardNumber)) {
			MyToast.getToast(context, "请输入支付宝账号").show();
			return false;
		}
		if ("-1".equals(securityQuestionId)) {
			MyToast.getToast(context, "请输入选择安全问题").show();
			return false;
		}
		if ("".equals(securityQuestionAnswer)) {
			MyToast.getToast(context, "请输入答案").show();
			return false;
		}
		return true;
	}
	
	

	/**
	 * 拿到 ID
	 * 
	 * @param index
	 * @param list
	 * @return
	 */
	private String getID(int index, List<Map<String, String>> list) {
		// 判断是否选择了省份
		if (index != -1) {
			for (Object o : list.get(index).entrySet()) {
				Map.Entry entry = (Map.Entry) o;
				String key = (String) entry.getKey();
				if ("id".equals(key)) {
					return (String) entry.getValue();
				}
			}
		}
		return "-1";
	}

	/**
	 * 点击监听
	 */
	class MyClickListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn_back:
				finish();
				break;
			case R.id.layout_mb:// 绑定手机号码
				Intent intent = new Intent(context, CheckPhoneNumber.class);
				context.startActivityForResult(intent, 0);
				break;
			/*
			 * case R.id.layout_yh://选择银行 spinner_bank = new
			 * MyBankSpinner(context, listBank, bank_index, App.BANK_TYPE,
			 * R.style.dialog); spinner_bank.show(); break; case
			 * R.id.layout_adress://选择银行支行地点 spinner_province = new
			 * MyBankSpinner(context, listProvince, province_index,
			 * App.PROVINCE_TYPE, R.style.dialog); spinner_province.show();
			 */
			// break;
			case R.id.accInfo_btn_improve:
				if (checkInfo()) {
					MyAsynTaskBind asynTaskBind = new MyAsynTaskBind();
					asynTaskBind.execute();
				}
				break;
			case R.id.bankinfo_btn_soft:// 选择安全问题
				spinner_question = new MyBankSpinner(context, listQuestion,
						question_index, App.QUESTION_TYPE, R.style.dialog);
				spinner_question.show();
				break;
			}
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
			if (data != null)
				accInfo_tv_mobilephone.setText(data.getStringExtra("mobile"));
		}
	}

	/**
	 * 异步任务 用来后台获取数据
	 */
	class MyAsynTask extends AsyncTask<Void, Integer, String> {

		@Override
		protected void onPreExecute() {
			dialog = BaseHelper.showProgress(AccountInformationActivity.this,
					null, "加载中..", true, false);
			dialog.show();
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(Void... params) {
			// 如果有绑定银行
			if (!chechBank()) {
				myHandler.sendEmptyMessage(0);// 没有绑定信息
			} else {
				myHandler.sendEmptyMessage(1);// 绑定了信息
			}
			return null;
		}

	}

	/**
	 * 获取站点名称和客服电话
	 */
	public void getSiteNameAndPhone() {
		RequestUtil requestUtil = new RequestUtil(context, false, 0) {
			@Override
			public void responseCallback(JSONObject jsonObject) {
				if (null != jsonObject) {
					String name = jsonObject.optString("SiteName");
					String phone = jsonObject.optString("Phone");
					if (!"".equals(name)) {
						App.APP_NAME = name;
					}
					if (!"".equals(phone)) {
						App.SERVICE_PHONE = phone;
					}
				} else {
					if (RequestUtil.DEBUG)
						Log.e(TAG, "获取站点名称和客服电话---返回结果为空");
				}
				tv_tip_info.setText("温馨提示：\n1、用户名以及手机号码是你登录的唯一凭证。"
						+ "\n2、真实姓名须同银行卡实名一致，身份证号码须同银行卡身份一致"
						+ "\n3、请放心填写真实的个人资料，我们会对你的身份信息进行严格保密。"
						+ "\n4、以上资料仅用于提款到银行卡，请真实填写否则无法完成提款。"
						+ "\n5、以上信息一经填写不能轻易修改，请确保填写正确。");
			}

			@Override
			public void responseError(VolleyError error) {
				if (RequestUtil.DEBUG)
					Log.e(TAG, "获取站点名称和客服电话出错--- " + error.getMessage());
				tv_tip_info.setText("温馨提示：\n1、用户名以及手机号码是你登录的唯一凭证。"
						+ "\n2、真实姓名须同银行卡实名一致，身份证号码须同银行卡身份一致"
						+ "\n3、请放心填写真实的个人资料，我们会对你的身份信息进行严格保密。"
						+ "\n4、以上资料仅用于提款到银行卡，请真实填写否则无法完成提款。"
						+ "\n5、以上信息一经填写不能轻易修改，请确保填写正确。");
			}
		};
		requestUtil.getSiteNameAndPhone();
	}

	/**
	 * 处理页面显示的
	 */
	class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			dialog.dismiss();
			switch (msg.what) {
			case 0:// 没有绑定信息
				findView();
				setEditTextEnabled(true);
				if (!"".equals(App.user.getName())) {
					accInfo_tv_uname.setText(App.user.getName());
					accInfo_tv_uname.setEnabled(false);
				}
				if (!"".equals(App.user.getMobile())) {
					accInfo_tv_mobilephone.setText(App.user.getMobile());
					layout_mobile.setVisibility(View.GONE);
					layout_mb.setEnabled(false);
				}
				if (!"".equals(App.user.getRealityName())) {
					tv_name.setText(App.user.getRealityName());
					tv_name.setEnabled(false);
				}
				if (!"".equals(App.user.getIdcardnumber())) {
					tv_cardNum.setText(App.user.getIdcardnumber());
					tv_cardNum.setEnabled(false);
				}
				if (!"".equals(App.user.getQqNumber())) {
					accInfo_tv_qqnumber.setText(App.user.getQqNumber());
					accInfo_tv_qqnumber.setEnabled(false);
				}

				break;
			case 1:// 绑定了信息
				findView();
				setEditTextEnabled(false);
				accInfo_tv_mobilephone.setText(App.user.getMobile());
				accInfo_tv_uname.setText(App.user.getName());
				accInfo_tv_qqnumber.setText(App.user.getQqNumber());
				tv_name.setText(App.user.getRealityName());
				tv_cardNum.setText(App.user.getIdcardnumber());
				// tv_bankLocation.setText(App.user.getProvinceName() +
				// "-"+ App.user.getCityName());
				// tv_fullName.setText(App.user.getFullName());
				tv_bankNum.setText(App.user.getBangNum());
				// tv_bankName.setText(App.user.getBankName());
				bankinfo_et_soft.setText(App.user.getSecurityQuestionId());
				bangkinfo_et_answer.setText("****");
				break;
			case 2:// 绑定信息成功
				String qid = question_index + "";
				Log.i(TAG, "问题的id------------->" + qid);
				App.user.setSecurityQuestionId(qid);
				Intent intent = new Intent(context, BindSuccessActivity.class);
				context.startActivity(intent);
				context.finish();
				break;
			case -100:// 绑定失败
				MyToast.getToast(getApplicationContext(), errormsg).show();
				errormsg = "";
				break;
			}
			super.handleMessage(msg);
		}
	}

	/**
	 * 判断银行信息 和省信息是否为空
	 */
	/*
	 * private boolean isFull() { boolean b = true; // 判断银行类型是否为空 if (bank_index
	 * != -1) { for (Object o : listBank.get(bank_index).entrySet()) { Map.Entry
	 * entry = (Map.Entry) o; String key = (String) entry.getKey(); if
	 * ("id".equals(key)) { bankTypeId = (String) entry.getValue(); } } } else {
	 * b = false; } // 判断是否选择城市 if (city_index != -1) { for (Object o :
	 * listCity.get(city_index).entrySet()) { Map.Entry entry = (Map.Entry) o;
	 * String key = (String) entry.getKey(); if ("id".equals(key)) { cityId =
	 * (String) entry.getValue(); } } } else { b = false; } return b; }
	 */

	/**
	 * 异步任务
	 */
	class MyAsynTaskBind extends AsyncTask<Void, Integer, String> {
		String error = "-1001";

		@Override
		protected String doInBackground(Void... params) {
			opt = "36";
			info = RspBodyBaseBean.changeBankinfo_info(mobile, uname, qqNumber,
					idCardNO, "3", "支付宝", bankCardNumber, "30", "348",
					realityName, securityQuestionId, securityQuestionAnswer);

			String key = App.key;
			crc = RspBodyBaseBean.getCrc(time, imei, key, info,
					App.user.getUid());
			auth = RspBodyBaseBean.getAuth(crc, time, imei,
					App.user.getUid());
			String[] values = { opt, auth, info };
			String result = HttpUtils.doPost(App.names, values,
					App.path);
			Log.i(TAG, "绑定信息的result----36----" + info);
			try {
				JSONObject ob = new JSONObject(result);
				if ("0".equals(ob.getString("error"))) {
					return "2";
				} else {
					errormsg = ob.getString("msg");
					return "-100";
				}
			} catch (Exception e) {
				VolleyLog.e("JSONObject Exception:%s , response:%s",
						e.toString(), result);
			}
			return error;
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = BaseHelper.showProgress(context, null, "绑定中....", true,
					true);
		}

		@Override
		protected void onPostExecute(String result) {
			if (dialog != null)
				dialog.dismiss();
			myHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}

	}

}
